﻿using System;
using System.Web;
using System.Configuration;
using System.Net.Mail;
using System.Net;

namespace Hired
{
    public static class Email
    {
        public static bool Send(string recipient, string subject, string body)
        {
            string from = ConfigurationManager.AppSettings["Username"];
            string server = ConfigurationManager.AppSettings["MailServer"];
            string password = ConfigurationManager.AppSettings["password"];

            MailMessage mail = new MailMessage(from, recipient);
            SmtpClient smtp = new SmtpClient(server, 587);
            NetworkCredential nc = new NetworkCredential(from, password);

            mail.Subject = subject;
            mail.IsBodyHtml = true;
            mail.Body = body;

            smtp.EnableSsl = true;
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = nc;

            try
            {
                smtp.Send(mail);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}